package com.aiju.cash.ui.enter;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiju.app.SimpleHttpCallback;
import com.aiju.base.activity.BaseTitleActivity;
import com.aiju.cash.R;
import com.aiju.cash.core.api.EnterApi;
import com.aiju.cash.ui.enter.entity.EnterShopInfo;
import com.aiju.cash.ui.multiple_shops.activity.ShopManagerActivity;
import com.aiju.cash.ui.multiple_shops.en.ShopManagerListType;
import com.aiju.common.image.AiJuImageLoaderProxy;
import com.aiju.utils.Util;

/**
 * @author: 佐为
 * @date: 2017-05-25 14:47
 * @version: V1.0
 * @Description: 入驻口碑
 */
public class EnterInfoActivity extends BaseTitleActivity {

    private TextView nameTextView, stateTextView;
    private ImageView logoImageView, obImageView;

    private EnterShopInfo enterShopInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_enter_info);
        setCenterTitle("入驻口碑");

        enterShopInfo = (EnterShopInfo) getIntent().getSerializableExtra("shop");

        nameTextView = (TextView) findViewById(R.id.tv_enter_name);
        stateTextView = (TextView) findViewById(R.id.tv_enter_state);
        logoImageView = (ImageView) findViewById(R.id.iv_enter_logo);
        obImageView = (ImageView) findViewById(R.id.iv_enter_ob);

        findViewById(R.id.btn_enter_look).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(EnterInfoActivity.this, CheckInActivity.class);
                intent.putExtra("enterShopInfo", enterShopInfo);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (enterShopInfo != null) {
            nameTextView.setText(enterShopInfo.getMain_shop_name());
            if (enterShopInfo.getReview_status().equals("0")) {
                stateTextView.setTextColor(Util.getColor(R.color.color_out));
                stateTextView.setText("审核状态：不通过");
            } else if (enterShopInfo.getReview_status().equals("1")) {
                stateTextView.setTextColor(Color.parseColor("#00a0e8"));
                stateTextView.setText("审核状态：已通过");
                obImageView.setSelected(true);
            } else if (enterShopInfo.getReview_status().equals("2")) {
                stateTextView.setTextColor(Color.parseColor("#42cf73"));
                stateTextView.setText("审核状态：正在审核");
            } else {
                stateTextView.setTextColor(Util.getColor(R.color.color_999999));
                stateTextView.setText("审核状态：未上传");//4
            }
            if (!TextUtils.isEmpty(enterShopInfo.getMain_image())) {
                new EnterApi(mDialogHelper).getImageInfo(enterShopInfo.getMain_image(), new SimpleHttpCallback() {
                    @Override
                    protected void onDataSuccess(String data) {
                        if (data.contains("分割线")) {
                            data = data.split("分割线")[1];
                            AiJuImageLoaderProxy.getInstance().displayImage(data, logoImageView, -1);
                        }
                    }
                });
            }
        }
    }

    @Override
    public void onBackPressed() {
        Intent intent = new Intent(this, ShopManagerActivity.class);
        Bundle b = new Bundle();
        b.putSerializable(ShopManagerActivity.FROM, ShopManagerListType.SHOPMANAGER);
        intent.putExtras(b);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }
}
